<%-- 
    Document   : mem_details
    Created on : Oct 7, 2009, 3:36:00 AM
    Author     : bharath
--%>
<jsp:useBean id ="ms" scope="session" class="Login.MySqlConnector"/>
<jsp:setProperty name="ms" property="*" />
<%@ page import="java.io.* ,java.util.*, java.sql.*, Login.* , javax.servlet.http.* , Registration.* " %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>SCF - Who's Who</title>
        <link rel="stylesheet" href="./css/yellow.css" />
        <link rel="stylesheet" href="./css/small.css" />
	<link href="style.css" rel="stylesheet" type="text/css" />

<!-- Loading Calendar JavaScript files -->

        <script type="text/javascript" src="./js/zapatec.js"></script>
        <script type="text/javascript" src="./js/calendar.js"></script>
        <!-- Loading language definition file -->
        <script type="text/javascript" src="./js/calendar-en.js"></script>
        <meta http-equiv="content-type" content="text/xml; charset=utf-8" />
    
        <script type="text/javascript">
            var d1;
            function getXMLObject()  //XML OBJECT
            {
                var xmlHttp = false;
                try {
                    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")  // For Old Microsoft Browsers
                }
                catch (e) {
                    try {
                        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")  // For Microsoft IE 6.0+
                    }
                    catch (e2) {
                        xmlHttp = false   // No Browser accepts the XMLHTTP Object then false
                    }
                }
                if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
                    xmlHttp = new XMLHttpRequest();        //For Mozilla, Opera Browsers
                }
                return xmlHttp;  // Mandatory Statement returning the ajax object created
            }

            var xmlhttp = new getXMLObject();	//xmlhttp holds the ajax object

            function getDistricts() {
                var sel = document.getElementById("state");
                var opt = sel.options[sel.selectedIndex];
                var d = opt.value || opt.text;
                if(xmlhttp) {
                    xmlhttp.open("GET","AJAXGetDistricts?state=" +d,true);
                    xmlhttp.onreadystatechange  = handleServerResponse;
                    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                    xmlhttp.send(null);
                }
            }

        /*    function getMandals() {
                var districts = document.getElementById("district");
                var opt1 = districts.options[districts.selectedIndex];
                var d1= opt1.value || opt1.text;
                alert(",,,,,,,,,,,,,,,,,,");
                if(xmlhttp) {
                    xmlhttp.open("GET","AJAXGetMandals?district=" +d1,true);
                    xmlhttp.onreadystatechange  = handleServerResponse1;
                    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                    xmlhttp.send(null);
                }
            }
          */
		    function getMemDetails()
            {
                var districts = document.getElementById("district");
                var opt1 = districts.options[districts.selectedIndex];
                var d1= opt1.value || opt1.text;
                	
				var profession = document.getElementById("prof");
                var opt2 = profession.options[profession.selectedIndex];
                var d2 = opt2.value || opt2.text;
									
				var sel = document.getElementById("state");
                var opt = sel.options[sel.selectedIndex];
                var d = opt.value || opt.text;
				                
                if(xmlhttp)
                {
                    xmlhttp.open("GET","AJAXGetMemDetails?district="+d1+"&state="+d+"&prof="+d2,true);
                    xmlhttp.onreadystatechange  = handleServerResponse2;
                    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                    xmlhttp.send(null);
                }
            }

            function handleServerResponse() {
                if (xmlhttp.readyState == 4) {
                    if(xmlhttp.status == 200) {
                        document.getElementById('district').options.length = 0;
                        var elemnt = document.getElementById("district");
                        var textToSplit = xmlhttp.responseText;
                        var returnElements=textToSplit.split("|");
                        var valueLabelPair=null;
                        document.getElementById('district').options[0] = new Option("Select","select");
                        for ( var i=0; i<(returnElements.length-1); i++ ){
                            valueLabelPair = returnElements[i].split("|");
                            document.getElementById('district').options[i+1] = new Option(valueLabelPair[0], valueLabelPair[1]);
                        }
                    }else {
                        alert("AJAX Call Error Please try again");
                    }
                }
            }

         /*   function handleServerResponse1() {
                if (xmlhttp.readyState == 4) {
                    if(xmlhttp.status == 200) {
                        document.getElementById('mandal').options.length = 0;
                        var elemnt = document.getElementById("mandal");
                        var textToSplit = xmlhttp.responseText;
                        var returnElements=textToSplit.split("|");
                        var valueLabelPair=null;
                        for ( var i=0; i<(returnElements.length-1); i++ ){
                            document.getElementById('mandal').options[i] = new Option("","");
                        }
                        document.getElementById('mandal').options[0] = new Option("Select","select");
                        for ( var i=0; i<(returnElements.length-1); i++ ){
                            valueLabelPair = returnElements[i].split("|");
                            document.getElementById('mandal').options[i+1] = new Option(valueLabelPair[0], valueLabelPair[1]);
                        }
                    }else {
                        alert("Error during AJAX call. Please try again");
                    }
                }
            }*/
            function handleServerResponse2() {
                if (xmlhttp.readyState == 4) {
                    if(xmlhttp.status == 200)
                    {
                        document.getElementById('doctors').options.length = 0;
                        var elemnt = document.getElementById("doctors");
                        var textToSplit = xmlhttp.responseText;
                        var returnElements=textToSplit.split("&");
						var valueLabelPair=null;
                        for ( var i=0; i<(returnElements.length-1); i++ )
						{
                            document.getElementById('doctors').options[i] = new Option("","");
                        }
                        document.getElementById('doctors').options[0] = new Option("Select","select");
                        for (var i=0; i<(returnElements.length-1); i++ )
						{                            
                           valueLabelPair = returnElements[i].split("&");
                           document.getElementById('doctors').options[i+1] = new Option(valueLabelPair[0], valueLabelPair[1]);
                        }
                    }
                    else
                      alert("Error during AJAX call. Please try again");
               }
            }
        </script>
    </head>
    <body>
	<a href="javascript:history.go(-1)">Back</a>
    <%
        HttpSession hs = request.getSession(true);
        String memid = (String) hs.getAttribute("memid");
        System.out.println("member id is " + memid);
	Connection con = ms.Connect();
        String q = "select distinct(profname) from proffession ;";
        PreparedStatement stmt1 = con.prepareStatement(q);
        System.out.println("query is : " + q);
        ResultSet rs1 = stmt1.executeQuery();
        String q1 = "select distinct(state) from states ;";
        System.out.println("query for states is : " + q1);
        PreparedStatement stmt2 = con.prepareStatement(q1);
    %>

    <a href = "Logout.jsp">Logout</a>
    <h1 align="left" class="style1"><span class="style8">Welcome :</span> <%=memid%></h1>
    <form action="SearchResult.jsp" method="post" name="form1" id="form1">
      <table width="430" height="198"  border="1" align="center" bordercolor="#FFFFFF" class="greenlink_no_left_padding">
        <tr>
          <th height="30" colspan="2" bgcolor="#D8F2C9" class="style1"><div align="center">Member Search </div></th>
        </tr>

        <tr>
          <th width="201" class="greentext">Name </th>
          <th width="227" class="style7">
              <input name="name" type="text" id="name"></th>
        </tr>

        <tr>
          <th height="30" class="greentext">Proffession </th>
          <th >
          <select name="prof" id="prof" onchange="javascript:getStates();" >
            <option> </option>
            <%while (rs1.next() == true) {%>
            <option><%=rs1.getString(1)%> </option>
            <%}%>
            </select></th>
        </tr>
        <tr class="greentext">
          <th colspan="2" class="style7"></th>
        </tr>

        <tr>
          <th height="31" class="greentext">State</th>
          <th class="style7"><select name="state" id="state" onchange="javascript:getDistricts();">
            <option></option>
		   <%
        ResultSet staters = stmt2.executeQuery();
        while (staters.next() == true) {%>
            <option><%=staters.getString(1)%></option>
            <%}%>
          </select></th>
        </tr>

        <tr>
          <th colspan="2" align="center"  bgcolor="#D8F2C9">
		    <div align="center">
		      <input type="Submit"  name="search" id="search" />		  
          </div></th>
        </tr>
      </table>
    </form>
	
    </body>
</html>

